﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace SanctusSoftware.Releases
{

  public class ReleaseInformation
  {

    public ReleaseInformation(Assembly assembly)
    {

      if (assembly == null)
      {
        throw new ArgumentNullException("assembly");
      }

      // Defaults
      ReleaseType = ReleaseType.Unknown;

      object[] releaseTypeAttributes = assembly.GetCustomAttributes(typeof(ReleaseTypeAttribute), false);
      if (releaseTypeAttributes != null && releaseTypeAttributes.Length > 0)
      {
        ReleaseTypeAttribute releaseTypeAttribute = (ReleaseTypeAttribute)releaseTypeAttributes[0];
        this.ReleaseType = releaseTypeAttribute.ReleaseType;
      }

      Version = assembly.GetName().Version.ToString();

      BuildDate = new DateTime(1982, 08, 15).AddDays(assembly.GetName().Version.Build);


    }

    public ReleaseType ReleaseType { get; internal set; }

    public string Version { get; private set; }

    public DateTime? BuildDate { get; private set; }

  }

}
